package com.aksu.system.controller.admin;


import com.aksu.server.dto.RoleUserDto;
import com.aksu.server.dto.PageDto;
import com.aksu.server.dto.ResponseDto;
import com.aksu.server.service.RoleUserService;
import com.aksu.server.util.ValidatorUtil;
import org.springframework.web.bind.annotation.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.annotation.Resource;

@RestController
@RequestMapping("/admin/roleUser")
public class RoleUserController {

private static final Logger LOG = LoggerFactory.getLogger(RoleUserController.class);
public static final String BUSINESS_NAME = "角色用户关联";

@Resource
private RoleUserService roleUserService;

@PostMapping("/list")
public ResponseDto roleUser(@RequestBody PageDto pageDto){
ResponseDto responseDto = new ResponseDto();
roleUserService.list(pageDto);
responseDto.setContent(pageDto);
return responseDto;
}

@PostMapping("/save")
public ResponseDto save(@RequestBody RoleUserDto roleUserDto){

// 保存校验
            ValidatorUtil.require(roleUserDto.getRoleId(), "角色");
            ValidatorUtil.require(roleUserDto.getUserId(), "用户");

ResponseDto responseDto = new ResponseDto();
roleUserService.save(roleUserDto);
responseDto.setContent(roleUserDto);
return responseDto;
}

@DeleteMapping("/delete/{id}")
public ResponseDto delete(@PathVariable String id){
ResponseDto responseDto = new ResponseDto();
roleUserService.delete(id);
return responseDto;
}
}
